<!DOCTYPE html>
<html>
    <head> 
	<meta charset="utf-8" />
	<title>Control</title>
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
	<script>

	    $(document).ready(function() {
		var getSettings = function(){
		$.ajax({
		    type: "GET",
		    url: "/settings.xml",
		    dataType: "xml",
		    success: function(xml) {
			$('#webport').val($(xml).find('webport').text());
			$('#controlport').val($(xml).find('controlport').text());
			$('#webroot').val($(xml).find('webroot').text());
			$('#defaultpage').val($(xml).find('defaultpage').text());
		    }
		});
		};

		$("form").on("submit", function(e)
		{
			e.preventDefault();
		    $.ajax({
			type: "POST",
			data: JSON.stringify({
				submit: $(this).find("[name=submit]").val(),
			    webport: $(this).find("[name=webport]").val(),
			    controlport: $(this).find("[name=controlport]").val(),
			    webroot : $(this).find("[name=webroot]").val(),
			    defaultpage : $(this).find("[name=defaultpage]").val()
			}),
			
			success: function(jqXHR, textStatus)
			{
			    alert("SUCCESS: " + textStatus);
			},
			error: function(jqXHR, textStatus, errorThrown)
			{
			    alert("ERROR: " + textStatus);
			}
		    }).done(function(){
			getSettings();
			});
		});
		getSettings();
	    });
	</script>
    </head>
    <body>
	<h1>Control</h1>
        <form method='POST'>
		<table>
            <tr><td>Web port:</td><td><input id="webport" type="text" name="webport"></td></tr>
            <tr><td>Control port:</td><td><input id="controlport" type="text" name="controlport" ></td></tr>
            <tr><td>Web root:</td><td><input id="webroot" type="text" name="webroot"></td></tr>
            <tr><td>Default page:</td><td><input id="defaultpage" type="text" name="defaultpage"></td></tr>
			<tr><td>&nbsp;</td><td><input type="submit" value="Ok" name="submit">
			<button onclick="location.href = '/log.html'">Show Log</button></td></tr>
			</form>
		</table>
        
	

    </body>
</html>
